/**
 * @Author admin
 * @Date 2019/4/2 15:55
 */

import java.util.Scanner;

public class test2 {


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine() ;
        int a  ;
        boolean ccc = false ;
        String h = null,min = null,ss = null ;

        for (; !s.equals("END");)
        {
            if (s.startsWith("$GPRMC"))
            {
                int loc = s.indexOf("*") ;
                String num = s.substring(loc + 1 ) ;
                s = s.substring(1, loc) ;
                String[] arr = s.split(",") ;
                if ( arr[2].equals("A") )
                {
                    a = s.charAt(0) ^ s.charAt(1) ;
                    for (int j = 2 ; j < s.length() ; j++ )
                    {
                        a ^= s.charAt(j)  ;
                    }
                    a %= 65536 ;
                    int f = Integer.parseInt(num, 16) ;
                    if (a == f)
                    {
                        ccc = true ;
                        h = s.substring(6, 8) ;
                        min = s.substring(8, 10) ;
                        ss = s.substring(10, 12) ;
                    }
                }
            }
            s = in.nextLine() ;
        }
        if (ccc)
        {
            int q = Integer.parseInt(h) ;
            if (q > 15 )
            {
                q = q - 15 ;
            }
            else
            {
                q += 8 ;
            }
            if (q < 10)
            {
                System.out.print("0"  );
            }
            System.out.print(q + ":") ;
            int w = Integer.parseInt(min) ;
            if (w < 10)
            {
                System.out.print("0"  );
            }
            System.out.print(w + ":") ;
            int e = Integer.parseInt(ss) ;
            if (e < 10)
            {
                System.out.print("0");
            }
            System.out.print( e ) ;

        }

    }

}


